package hlhj.fhp.supreme.fragment

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.PhoneBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import kotlinx.android.synthetic.main.tips_fgm.view.*

/**
 * Created by Administrator on 2018\3\7 0007.
 */
class TipsFgm :Fragment() {
    private lateinit var rootView:View
    private var ok=true
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        rootView=inflater.inflate(R.layout.tips_fgm,null)
//        settings.javaScriptEnabled=true
        rootView.webView.settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        rootView.webView.webViewClient=object :WebViewClient(){

        }
        OkGo.post<PhoneBean>(Urls.BaseUrl+Urls.PHONE)
                .params("type","prompt")
                .execute(object :JsonCallBack<PhoneBean>(activity){
                    override fun onSuccess(response: Response<PhoneBean>?) {
                        val bean = response?.body()
                        if (bean?.code==1){
                            var prompt = bean?.data.prompt
                            prompt=prompt.replace("<img", "<img style='max-width:100%;height:auto;'")
                            rootView.webView.loadDataWithBaseURL(null, prompt,"text/html", "utf-8", null)
                        }
                    }
                })
        return rootView
    }
}